package com.dba.example.rest;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dba.entities.Account;
import com.dba.repositories.AccountRepository;
import com.dba.views.Views;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;

@Component
@Path("/account")
public class AccountService {

	@JsonIgnore
	@Autowired
	private AccountRepository rep;
	
	@GET
	@Path("/list")
	@Produces(MediaType.APPLICATION_JSON)
	@JsonView({ Views.List.class })
	public List<Account> list() {
		return rep.findAll();
	}

	@GET
	@Path("/get")
	@Produces(MediaType.APPLICATION_JSON)
	@JsonView({ Views.Detailed.class })
	public Account get(@QueryParam("id") Integer id) {
		return rep.findOne(id);
	}

	@GET
	@Path("/listX")
	@Produces(MediaType.APPLICATION_XML)
	@JsonView({ Views.List.class })
	public List<Account> listX() {
		return rep.findAll();
	}

	@GET
	@Path("/getX")
	@Produces(MediaType.APPLICATION_XML)
	@JsonView({ Views.Detailed.class })
	public Account getX(@QueryParam("id") Integer id) {
		return rep.findOne(id);
	}

}
